package test03;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class t2 {
    public static void main(String[] args) {
        //1.定义List集合，在List集合中增加三个员工信息
        List<Worker> list = new ArrayList<Worker>();
        list.add(new Worker("凤姐",18,20000));
        list.add(new Worker("欧阳峰",60,8000));
        list.add(new Worker("刘德华",40,30000));
        System.out.println(list);
        System.out.println("-----------------------------------------------------");

        //2.在"欧阳峰"之前插入一个员工，信息为：姓名："张柏芝"，年龄：35，工资3300
        list.add(1, new Worker("张柏芝",35,3300));
        System.out.println(list);
        System.out.println("-----------------------------------------------------");

        //3.删除"刘德华"的信息
        list.remove(new Worker("刘德华",40,30000));
        System.out.println(list);
        System.out.println("-----------------------------------------------------");

        //4.利用for 循环遍历，打印List 中所有员工的信息
        for(int j = 0; j<list.size(); j++) {
            Worker work = list.get(j);
            System.out.println(work);
        }
        System.out.println("-----------------------------------------------------");

        //5.利用迭代遍历，对List 中所有的员工调用work 方法
        Iterator<Worker> work = list.iterator();
        while(work.hasNext()) {
            Worker w1 = work.next();
            w1.work();
        }

    }
}
